package com.sun.controller.admin;


import com.alibaba.fastjson.JSON;
import com.sun.pojo.Checkin;
import com.sun.pojo.Employee;
import com.sun.service.CheckinService;
import com.sun.utils.DataGridViewResult;
import com.sun.utils.SystemConstant;
import com.sun.vo.CheckinVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

@RestController
@RequestMapping("/admin/checkin")
public class CheckinController {

    @Autowired
    private CheckinService checkinService;

    @RequestMapping("/list")
    public DataGridViewResult list(CheckinVo checkinVo){
        return checkinService.list(checkinVo);
    }

    @RequestMapping("/addCheckin")
    public String addCheckin(Checkin checkin, HttpSession session){
        Employee employee = (Employee) session.getAttribute(SystemConstant.LOGINUSER);
        checkin.setCreatedby(employee.getId());
        HashMap<String, Object> map = new HashMap<String, Object>();
        if(checkinService.addCheckin(checkin)>0){
            map.put(SystemConstant.SUCCESS,true);
            map.put(SystemConstant.MESSAGE,"办理入住成功!");
        }else{
            map.put(SystemConstant.SUCCESS,true);
            map.put(SystemConstant.MESSAGE,"办理入住失败!");
        }
        return JSON.toJSONString(map);
    }
}
